package com.cfets.annualAssessment.conf;

import com.cfets.annualAssessment.entity.AnnualInform;
import com.cfets.annualAssessment.service.AnnualInformService;
import com.cfets.annualAssessment.util.Constant;
import com.cfets.annualAssessment.util.SmsSDKDemo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by ShenYiChou on 2017/6/7.
 */
@Component
//@EnableScheduling // 启用定时任务
public class SchedulingConfig {
    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private AnnualInformService annualInformService;

//    @Scheduled(cron = "0/20 * * * * ?") // 每20秒执行一次
    public void scheduler() {
        String temp_str="";
        Date dt = new Date();
        ArrayList<String> phoneNumbers=new ArrayList<>();
        ArrayList<String> names=new ArrayList<>();
        AnnualInform annualInform=new AnnualInform();
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
        temp_str=sdf.format(dt);
        logger.info(temp_str);
        //test 要关掉
        temp_str="06-24";//test
        annualInform.setBirth_date(temp_str);
        List<AnnualInform> annualInformList=this.annualInformService.getAnnualInform(annualInform);
        phoneNumbers.addAll(annualInformList.stream().map(AnnualInform::getMobile).collect(Collectors.toList()));
        names.addAll(annualInformList.stream().map(AnnualInform::getName).collect(Collectors.toList()));
        Map<String,ArrayList<String>> SMSMap=new HashMap<>();
        SMSMap.put("phone",phoneNumbers);
        SMSMap.put("name",names);
        SmsSDKDemo.SMSSenderUtil(SMSMap, Constant.BIRTH_SMS_ID);
    }

}
